<template>
  <div class="header_container">
    <div class="top_left" @click="toHome">
      <img src="../../assets/logo_headee.jpeg" alt="" />
      <span>晓文信息科技有限公司</span>
    </div>
    <div class="top_right">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <div class="header_logo">
            <img src="../../assets/logo.png" alt="" />
            <span class="head_username">{{ user.username }}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item icon="el-icon-plus" command="userinfo"
            >个人中心</el-dropdown-item
          >
          <el-dropdown-item icon="el-icon-circle-check" command="logout"
            >注销</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: null,
    };
  },
  created() {
    debugger;
    this.user = JSON.parse(window.sessionStorage.getItem("currentLoginInfo"));
  },
  methods: {
    handleCommand(command) {
      if (command === "logout") {
        window.sessionStorage.removeItem("token");
        this.$router.push("/login");
        this.$message.warning("注销成功");
      } else if (command === "userinfo") {
        this.$router.push("/user/userinfo");
      }
    },
    toHome() {
      const token = window.sessionStorage.getItem("token");
      if (token !== "") {
        this.$router.push("/login");
      }
      this.$router.push("/home");
    },
  },
};
</script>

<style scoped>
.header_container {
  display: flex;
  justify-content: space-between;
}
.top_left,
.header_logo,
.top_right {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.top_left img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
.top_left span {
  display: flex;
  align-items: center;
  margin-left: 15px;
  font-size: 20px;
}
.header_logo img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
</style>
